package juc.delayqueue;

import java.util.concurrent.DelayQueue;

/**
 * @author 王霄
 * @date 2022/7/23 19:09
 */
public class OrderRunner implements Runnable {
    private final static DelayQueue<OrderDelayed> DELAY_QUEUE = new DelayQueue<>();
    public void add(OrderDelayed orderDelayed) {
        DELAY_QUEUE.add(orderDelayed);
    }

    @Override
    public void run() {
        OrderDelayed orderDelayed;
        while (true) {
            try {
                //从延时队列中获取已经超时的数据
                orderDelayed = DELAY_QUEUE.take();
                String orderId = orderDelayed.getOrderId();
                System.out.printf("订单号：%s,3分钟内未支付%n", orderId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
